<?php
/**
 * Created by PhpStorm.
 * User: chenxiaogang
 * Date: 2017/11/17
 * Time: 上午11:58
 */

namespace User\Model;


use Common\Model\CommonModel;

class User extends CommonModel
{
    protected $trueTableName='cmf_users';

    /**
     * @use          [得到管理员列表，指定id范围]
     * @author       chenxiaogang
     * @param $in
     * @return mixed
     */
    public function getbyIn($in)
    {
        $where = [
            'id' => [ 'in', $in ],
            'user_status' => 1,
        ];
        $data = $this->where( $where )->getField('id,user_login',true);
        return $data;
    }
    /**
     * @use          [得到管理员列表，指定id范围 - 不做getField处理]
     * @author       chenxiaogang
     * @param $in
     * @param   $fields [要查的列]
     * @return mixed
     */
    public function getListByIn($in,$fields = 'id,user_login')
    {
        $where = [
            'id' => [ 'in', $in ],
            'user_status' => 1,
        ];
        $data = $this->where( $where )->field($fields)->select();
        return $data;
    }

    public static function getAccountStatusText($key){
        $status = [
            0 => '未认证',
            1 => '已认证',
            2 => '认证未通过',
            3 => '暂时不需要',
            4 => '未联系上客户',
        ];
        if(!array_key_exists( $key, $status )) {
            return '未知状态';
        }
        return $status[(int)$key];
    }

    public static function getUserTypeText($key){
        $status = [
            0 => '待绑卡',
            1 => '上传证件照',
            2 => '待审核',
            3 => '学信认证',
            4 => '填写联系信息',
            5 => '信息填写完成',
            8 => '系统审核不通过',
        ];
        if(!array_key_exists( $key, $status )) {
            return '未知状态';
        }
        return $status[(int)$key];
    }
    public static function getBorrTypeText($key){
        $status = [
            0 => '待申请借款',
            1 => '待填写运营商',
            2 => '借款中',
            2 => '审核不通过',
        ];
        if(!array_key_exists( $key, $status )) {
            return '未知状态';
        }
        return $status[(int)$key];
    }

    /**
     * @use          [指定角色范围的所有用户]
     * @author       chenxiaogang
     * @param $roleIds
     * @return mixed
     */
    public function getUsersByInRoleIds($roleIds)
    {
        $ids = M('role_user','cmf_')->where(['role_id'=>['in',$roleIds]])->getField('user_id',true);
        $data = $this->where(['id'=>['in',$ids]])->getField('id,user_login');
        return $data;
    }
    
}